package com.mall.admin.controller;

import com.mall.admin.service.PmsProductCategoryService;
import com.mall.commons.utils.R;
import com.mall.vo.PmsProductCategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/productCategory")
public class PmsProductCategoryController {

    @Autowired
    private PmsProductCategoryService pmsProductCategoryService;

    /**
     * 查询所有一级分类及子分类
     * @return
     */
    @GetMapping("/list/withChildren")
    public R listWithChildren(){
        return pmsProductCategoryService.listWithChildren();
    }

    /**
     * 添加商品分类
     * @param categoryVo
     * @return
     */
    @PostMapping("/create")
    public R create(@RequestBody PmsProductCategoryVo categoryVo){
        return pmsProductCategoryService.create(categoryVo);
    }

    /**
     * 删除商品
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public R deleteById(@PathVariable Long id){
        return pmsProductCategoryService.deleteById(id);
    }

    /**
     * 分页查询商品分类
     * @param pageNum
     * @param pageSize
     * @param parentId
     * @return
     */
    @GetMapping("/list/{parentId}")
    public R listParentId(@RequestParam(defaultValue = "1") Integer pageNum,
                          @RequestParam(defaultValue = "10") Integer pageSize,
                          @PathVariable Long parentId){
        return pmsProductCategoryService.listParentId(pageNum,pageSize,parentId);
    }

    /**
     * 修改导航栏显示状态
     * @param ids
     * @param navStatus
     * @return
     */
    @PostMapping("/update/navStatus")
    public R updateNavStatus(@RequestParam("ids") List<Long> ids, Integer navStatus){
        return pmsProductCategoryService.updateNavStatus(ids,navStatus);
    }

    /**
     * 修改显示状态
     * @param ids
     * @param showStatus
     * @return
     */
    @PostMapping("/update/showStatus")
    public R updateShowStatus(@RequestParam("ids")List<Long> ids,Integer showStatus){
        return pmsProductCategoryService.updateShowStatus(ids,showStatus);
    }

    /**
     * 修改商品分类
     * @param categoryVo
     * @param id
     * @return
     */
    @PostMapping("/update/{id}")
    public R updateById(@RequestBody PmsProductCategoryVo categoryVo,@PathVariable Long id){
        return pmsProductCategoryService.updateById(categoryVo,id);
    }

    /**
     *根据id获取商品分类
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public R findById(@PathVariable Long id){
        return pmsProductCategoryService.findById(id);
    }}
